package cn.net.msg.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import cn.net.msg.dao.TbNewsDao;
import cn.net.msg.model.TbFavourite;
import cn.net.msg.model.TbNewslistUrl;
import cn.net.msg.service.base.DaoSupport;

@Component("tbNewsDao")
public class TbNewsDaoImpl extends DaoSupport implements TbNewsDao {

    private static final Log log = LogFactory.getLog(TbNewsDaoImpl.class);

    @Override
    public TbNewslistUrl getNewsListUrl(int newstype, int currentpage) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("newsTypeId", newstype);
        params.put("currentPage", currentpage);
        List<TbNewslistUrl> list = super.queryByProperty(TbNewslistUrl.class,params);
        if (list.size() == 0) {
            return null;
        } else {
            return list.get(0);  
        }
    }

    @Override
    public boolean checkIsExistFavouriteRecord(TbFavourite tbFavourite) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("favouritelistUserid", tbFavourite.getFavouritelistUserid());
        params.put("favouritelistUrl", tbFavourite.getFavouritelistUrl());

        List<TbFavourite> list = super.queryByProperty(TbFavourite.class, params);
        return list.size() > 0;
    };

    @Override
    public void addFavouriteNews(TbFavourite tbFavourite) {
        super.save(tbFavourite);
    }
}
